/*
@STI LICENSE
(C) 2006-2008 Universit�t Innsbruck.

This file is part of myOntology.

myOntologyis free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

myOntologyis distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with myOntology.  If not, see <http://www.gnu.org/licenses/>.

@STI LICENSE */
/**
 * 
 */
package org.myontology.controller;

/**
 * @author <a href="michael.hackl@sti2.at">Michael Hackl</a>
 * Project: Myontology - www.myontology.org
 * STI
 *
 */
public abstract class AbstractLifeCycleController implements LifeCycleController {

	public ValueHandler<LifeCycle> LIFE_CYCLE = new ValueHandler<LifeCycle>(AttributeLevel.REQUEST,this);
	
	/* (non-Javadoc)
	 * @see org.myontology.controller.LifeCycleController#clean(org.myontology.controller.AttributeHolder)
	 */
	public void finish(AttributeHolder attributes) {
		LIFE_CYCLE.getValue(attributes).finish();

	}
	
	/* (non-Javadoc)
	 * @see org.myontology.controller.LifeCycleController#clean(org.myontology.controller.AttributeHolder)
	 */
	public void clean(AttributeHolder attributes) {
		LIFE_CYCLE.getValue(attributes).clean();

	}

	/* (non-Javadoc)
	 * @see org.myontology.controller.LifeCycleController#init(org.myontology.controller.AttributeHolder)
	 */
	public void init(AttributeHolder attributes) {
		if (LIFE_CYCLE.getValue(attributes)==null) {

			LifeCycle l = create(attributes);
			l.init();
			LIFE_CYCLE.setValue(attributes, l);
		}
	}

	/* (non-Javadoc)
	 * @see org.myontology.controller.DependencyProvider#get(java.lang.Object)
	 */
	public LifeCycle get(Object action,AttributeHolder attributes) {
		return LIFE_CYCLE.getValue(attributes);
	}

	public abstract LifeCycle create(AttributeHolder attributes);
	
}
